var e = require;
var t = module;
var o = exports;
var Adv_skd=require("./Adv_skd");
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("GlobalParams"),
    a = e("HardData"),
    i = e("HardKey"),
    r = e("AnalyticsManager"),
    s = e("AssetsManager"),
    l = e("nameCfg"),
    c = e("CommonHelper"),
    d = e("sdkConfig"),
    h = e("Game"),
    _ = e("Loader"),
    u = e("RoleSoldierInfo"),
    p = cc._decorator,
    m = p.ccclass,
    f = p.property,
    g = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.loading_bar = null),
                (t.loading_label = null),
                (t.tip_label = null),
                (t.preBundleList = [
                    "Texture",
                    "Atlas",
                    "animation",
                    "Role",
                    "SceneMain",
                    "guide",
                    "role_sound",
                    "fight",
                    "roles_prefabs"
                ]),
                (t.necessaryBundleList = ["Texture", "Atlas", "animation", "Role", "SceneMain", "guide"]),
                (t.bundleLoadState = {}),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.onLoad = function () {
                console.log('loading onload');
                (cc.director.getCollisionManager().enabled = !0), (cc.director.getPhysicsManager().enabled = !0);
            }),

            (t.prototype.start = function () {
                Adv_skd.default.instance.getWxIdFromServer(()=>{
                    this.selfstart()
                },()=>{
                    this.selfstart()
                })
            }),

            (t.prototype.selfstart = function () {
                console.log('loading start');
                (n.GlobalParams.gameSound = new a.default(n.GlobalParams.game_name + i.DataKey.Sound, !0)),
                    (n.GlobalParams.gameMusic = new a.default(n.GlobalParams.game_name + i.DataKey.Music, !0)),
                    (n.GlobalParams.gameShock = new a.default(n.GlobalParams.game_name + i.DataKey.Short, !0)),
                    (n.GlobalParams.addDeskIcon = new a.default(
                        n.GlobalParams.game_name + i.DataKey.addDeskTopIsOn,
                        !1
                    )),
                    (n.GlobalParams.showPrivacy = new a.default(n.GlobalParams.game_name + i.DataKey.show_privacy, !1)),
                    (n.GlobalParams.ShareVidoeInfo = new a.default(
                        n.GlobalParams.game_name + i.DataKey.share_video,
                        0
                    )),
                    (n.GlobalParams.JoinGuideMode = new a.default(n.GlobalParams.game_name + i.DataKey.guide_mode, !0)),
                    (n.GlobalParams.PlayerInfo = new a.default(n.GlobalParams.game_name + i.DataKey.PlayerInfo, {
                        coin: 200,
                        zs: 0,
                        name: "",
                        level: 1,
                        exp: 0,
                        head: 1,
                        have_head: [1, 2, 3, 4, 5],
                        change_mode: 0,
                        revive: 5,
                        unlock_skill: [1, 2]
                    }));
                var e = n.GlobalParams.PlayerInfo.value;
                if (
                    ("" == e.name &&
                        ((e.name = l.default.nameList[c.default.getRandomInt(0, 10)]),
                        (n.GlobalParams.PlayerInfo.value = e)),
                    (n.GlobalParams.PlayerSigninInfo = new a.default(n.GlobalParams.game_name + i.DataKey.signin_info, {
                        signin_num: 0,
                        signin_date: 0
                    })),
                    (n.GlobalParams.playerSkinInfo = new a.default(
                        n.GlobalParams.game_name + i.DataKey.player_skin_info,
                        {use: [5], have: {hero: [5], taste_card: 0}}
                    )),
                    (n.GlobalParams.LuckyBoxInfo = new a.default(n.GlobalParams.game_name + i.DataKey.lucky_box_info, {
                        last_award: !0,
                        gift_num: 0,
                        open_today: 0,
                        get_day: 0
                    })),
                    (n.GlobalParams.ShopDowerInfo = new a.default(
                        n.GlobalParams.game_name + i.DataKey.shop_dower_info,
                        {info: [], now_date: 0, free: !0}
                    )),
                    (n.GlobalParams.PlayerDowerInfo = new a.default(
                        n.GlobalParams.game_name + i.DataKey.player_dower_info,
                        {dower: [1, 1, 1, 1, 1], debris: [0, 0, 0, 0, 0]}
                    )),
                    (n.GlobalParams.PlayerTaskInfo = new a.default(
                        n.GlobalParams.game_name + i.DataKey.player_task_info,
                        {schedule: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], today: 0, box_award: [0, 0, 0, 0, 0]}
                    )),
                    n.GlobalParams.PlayerTaskInfo.value.today != new Date().toLocaleDateString())
                ) {
                    var t = n.GlobalParams.PlayerTaskInfo.value;
                    (t.schedule = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
                        (t.today = new Date().toLocaleDateString()),
                        (t.box_award = [0, 0, 0, 0, 0]),
                        (n.GlobalParams.PlayerTaskInfo.value = t);
                }
                (n.GlobalParams.PlayerSeasonInfo = new a.default(
                    n.GlobalParams.game_name + i.DataKey.player_season_info,
                    {free_award: [], extra_award: []}
                )),
                    (n.GlobalParams.GameHeroIndex = []);
                var o = [];
                d.default.platform == d.EPlatform.TikTok && ((n.GlobalParams.showPrivacy.value = !0), (o = [0, 2, 12]));
                for (var s = 0; s < u.default.Role_info.length; s++)
                    -1 == o.indexOf(s) && n.GlobalParams.GameHeroIndex.push(s);
                d.default.platform != d.EPlatform.No_AD &&
                    d.default.platform != d.EPlatform.test &&
                    (r.default.getInstance().init(r.EAnalyticsSDKType.CoCos),
                    r.default.getInstance().login(r.EAnalyticsEvent.Start),
                    r.default.getInstance().login(r.EAnalyticsEvent.Success),
                    r.default
                        .getInstance()
                        .raiseCustomEvent(r.EAnalyticsEvent.Success, {name: "事件一", info: "进入主场景"})),
                    (n.GlobalParams.start_time = new Date().getTime()),
                    this.showTipInfo(),
                    this.loadBundle();
            }),
            (t.prototype.loadBundle = function () {
                for (
                    var e = this,
                        t = function (t) {
                            _.default.loadSubpackage(
                                o.necessaryBundleList[t],
                                function () {
                                    e.loadOneSubpackage(e.necessaryBundleList[t]);
                                },
                                !0
                            );
                        },
                        o = this,
                        n = 0;
                    n < this.necessaryBundleList.length;
                    ++n
                )
                    t(n);
                n = 0;
                for (var a = this.preBundleList.length; n < a; ++n)
                    _.default.loadBundle(this.preBundleList[n], null, !1, !1);
            }),
            (t.prototype.loadOneSubpackage = function (e) {
                this.bundleLoadState[e] = !0;
                for (var t = 0, o = 0; o < this.necessaryBundleList.length; o++)
                    this.bundleLoadState[this.necessaryBundleList[o]] && t++;
                t == this.necessaryBundleList.length && this.changeScene();
            }),
            (t.prototype.changeScene = function () {
                return __awaiter(this, void 0, void 0, function () {
                    var e = this;
                    return __generator(this, function (t) {
                        switch (t.label) {
                            case 0:
                                return (
                                    this.setProgress(),
                                    this.setLabel("加载游戏图集。。。"),
                                    [4, s.default.getInstance().loadFolder("Atlas", s.AssetsType.Atlas)]
                                );
                            case 1:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载游戏预支资源。。。"),
                                    [4, s.default.getInstance().loadFolder("SceneMain", s.AssetsType.Bundle)]
                                );
                            case 2:
                                return (
                                    t.sent(),
                                    n.GlobalParams.JoinGuideMode.value
                                        ? [4, s.default.getInstance().loadFolder("guide", s.AssetsType.Bundle)]
                                        : [3, 5]
                                );
                            case 3:
                                return (
                                    t.sent(),
                                    [4, s.default.getInstance().loadFolder("sound/guide_sound", s.AssetsType.Audio)]
                                );
                            case 4:
                                t.sent(), (t.label = 5);
                            case 5:
                                return (
                                    this.setProgessOver(),
                                    this.setLabel("加载音效资源。。。"),
                                    [4, s.default.getInstance().loadFolder("sound/main_sound", s.AssetsType.Audio)]
                                );
                            case 6:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载主场景资源。。。"),
                                    cc.director.preloadScene("Main", null, function (t) {
                                        t
                                            ? console.error("======场景加载错误========", t)
                                            : (e.unscheduleAllCallbacks(),
                                              cc
                                                  .tween(e.loading_bar)
                                                  .to(0.2, {width: 690})
                                                  .call(function () {
                                                      if (n.GlobalParams.showPrivacy.value)
                                                          cc.director.loadScene("Main");
                                                      else {
                                                        cc.director.loadScene("Main");
                                                        //   var t = s.default.getInstance().getPrefabNode("tip_view_ui");
                                                        //   e.node.parent.addChild(cc.instantiate(t));
                                                      }
                                                  })
                                                  .start());
                                    }),
                                    [2]
                                );
                        }
                    });
                });
            }),
            (t.prototype.setLabel = function (e) {
                this.loading_label.string = e;
            }),
            (t.prototype.setProgress = function () {
                var e = this;
                this.unscheduleAllCallbacks(),
                    (this.loading_bar.width = 0),
                    this.schedule(function () {
                        cc.tween(e.loading_bar)
                            .by(0.2, {width: 10})
                            .call(function () {
                                e.loading_bar.width >= 660 && e.unscheduleAllCallbacks();
                            })
                            .start();
                    }, 0.2);
            }),
            (t.prototype.setProgessOver = function () {
                var e = this;
                this.unscheduleAllCallbacks(),
                    cc
                        .tween(this.loading_bar)
                        .to(0.2, {width: 690})
                        .call(function () {
                            e.setProgress();
                        })
                        .start();
            }),
            (t.prototype.showTipInfo = function () {
                var e = this;
                (this.tip_label.string =
                    h.default.login_tip_list[c.default.getRandomInt(0, h.default.login_tip_list.length - 1)]),
                    cc
                        .tween(this.tip_label)
                        .delay(3)
                        .call(function () {
                            e.showTipInfo();
                        })
                        .start();
            }),
            __decorate([f(cc.Node)], t.prototype, "loading_bar", void 0),
            __decorate([f(cc.Label)], t.prototype, "loading_label", void 0),
            __decorate([f(cc.Label)], t.prototype, "tip_label", void 0),
            __decorate([m], t)
        );
    })(cc.Component);
o.default = g;
